Pro CDI 2 in Java EE 8 by Jan Beernink & Arjan Tijms

Pro CDI 2 in Java EE 8 by Jan Beernink & Arjan Tijms

Author:Jan Beernink & Arjan Tijms
Language: eng
Format: epub
ISBN: 9781484243633
Publisher: Apress


It is important that if the get(Contextual<T> contextual, CreationalContext<T> creationalContext) method creates a new bean instance, this must be done using the given contextual and creational context instances. You may be wondering why CreationalContext must be passed as an argument here. The main reason for this is that this associates the given bean instance with the creational context. The CreationalContext interface has a release() method, which triggers all beans associated with that creational context to be destroyed. This is primarily used to destroy any @Dependent-scoped beans. These are associated with the creational context of the instance they are injected in. When that instance is destroyed, release() is called on CreationalContext, which causes the @Dependent-scoped beans to be destroyed.

You may notice that the Context interface does not have any methods to start, suspend, or destroy a scope instance. The main reason for this is that the methods in the Context interface are meant to be called only by the CDI container. Starting, suspending, or destroying a scope instance depends on the implementation of the scope and as such is not a concern of the CDI container. This does not mean that the context object can’t have methods that control the scope. On the contrary, if such methods are needed, the context object is the most logical place to put them as the context object is responsible for maintaining the scope. However, as these methods are called by library or application code and different scopes may have different requirements for such methods, these methods are not defined in the Context interface.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.